#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>


int main(int argc, char *argv[])
{
	FILE *fp;
	int led_no;

	if(argc != 3)
	{
		printf("Usage: %s <led_no> <on/off>\n",argv[0]);
		exit(0);
	}

	led_no = strtoul(argv[1],0,0);

	switch (led_no)
	{
		case 2:
			fp = fopen("/sys/class/leds/green/brightness","w");
			break;
		case 3:
			fp = fopen("/sys/class/leds/yellow/brightness","w");
			break;
		case 4:
			fp = fopen("/sys/class/leds/red/brightness","w");
			break;
		default:
			printf("err: no target led!\n");
			break;
	}

	if(fp == NULL)
	{
		printf("err: cant open the file\n");
		exit(0);
	}

	if(!strcmp(argv[2],"on")){
		fputc('1',fp);
		printf("led%d on!\n",led_no);
	}else if(!strcmp(argv[2],"off")){
		fputc('0',fp);
		printf("led%d off!\n",led_no);
	}

	fclose(fp);

	return 0;
}

